<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <title>新增权限</title>
    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport"
          content="width=device-width, initial-scale=1.0, minimum-scale=1.0, maximum-scale=1.0, user-scalable=0">
    <link rel="stylesheet" href="__STATIC__/layuiadmin/layui/css/layui.css" media="all">
    <link rel="stylesheet" href="__STATIC__/layuiadmin/style/admin.css" media="all">
</head>
<body>

<div class="layui-fluid">
    <div class="layui-row layui-col-space15">
        <div class="layui-col-md12">
            <div class="layui-card">
                <div class="layui-card-header">{:lang('add_role')}</div>
                <div class="layui-card-body" pad15>
                    <div class="layui-form" lay-filter="user">
                        <div class="layui-form-item">
                            <label class="layui-form-label">{:lang('belong to the superior')}</label>
                            <div class="layui-input-inline">
                                <select name="parent_id" lay-verify="required">
                                    <option value="0">{:lang('top role')}</option>
                                    {volist name="data" id="value"}
                                    <option value="{$value.id}|{$value.level}">{$value.role_name}</option>
                                    {/volist}
                                </select>
                            </div>
                            <div class="layui-form-mid layui-word-aux"></div>
                        </div>
                        <div class="layui-form-item">
                            <label class="layui-form-label">{:lang('role_name')}</label>
                            <div class="layui-input-inline">
                                <input type="text" name="role_name" lay-verify="required" autocomplete="off"
                                       class="layui-input">
                            </div>
                        </div>

                        <div class="layui-form-item">
                            <label class="layui-form-label">{:lang('auth_list')}</label>
                            <div class="layui-input-block" id="xtree1">
                            </div>
                        </div>
                        <hr>

                        <div class="layui-form-item">
                            <div class="layui-input-block">
                                <button class="layui-btn" lay-submit lay-filter="addauthinfo">立即提交</button>
                                <button type="reset" class="layui-btn layui-btn-primary">重新填写</button>
                            </div>
                        </div>
                    </div>

                </div>
            </div>
        </div>
    </div>
</div>

<script src="__STATIC__/layuiadmin/layui/layui.js"></script>
<script type="text/javascript" src="__STATIC__/layuiadmin/layui-xtree.js"></script>
<script>
    layui.config({
        base: '__STATIC__/layuiadmin/' //静态资源所在路径
    }).extend({
        index: 'lib/index' //主入口模块
    }).use(['index', 'form', 'layer', 'jquery'], function () {
        var form = layui.form;
        var layer = layui.layer;
        var $ = layui.jquery;
        form.on('submit(addauthinfo)', function (data) {
            var load = layer.load(0, {
                shade: 0.5
            });
            $.ajax({
                url : "{:url('Api/role/add')}",
                data: data.field,
                type: "post",
                dataType:"json",
                success:function (res) {
                    layer.close(load);
                    if (res.code === '200'){
                        layer.msg(res.msg);
                        //刷新页面
                        window.location.reload(true);
                        return ;
                    }else{
                        layer.msg(res.msg);
                        return ;
                    }
                }
            });
            return false;
        });

        $.post("{:url('api/role/auth_json')}",{},function (res) {
            var res_ = JSON.parse(res);
            if(res_.code == 200)
            {
                //1、最基础的用法 - 直接绑定json
                var xtree1 = new layuiXtree({
                    elem: 'xtree1'   //(必填) 放置xtree的容器，样式参照 .xtree_contianer
                    , form: form     //(必填) layui 的 from
                    , data: res_.data.all     //(必填) json数据
                });
            }
        });

    });
</script>
</body>
</html>